package ren.xxpure.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import ren.xxpure.entity.CommonResult;
import ren.xxpure.entity.User;
import ren.xxpure.service.UserService;

import javax.annotation.Resource;

@Api("用户接口")
@RestController()
@Slf4j
public class UserController {

	@Resource
	UserService userService;


	@ApiOperation("登录接口返回token")
	@GetMapping("/login")
	public CommonResult<String> login(String userName, String password) {
		return this.userService.login(userName, password);
	}

	@ApiOperation("登出")
	@PostMapping("/logout")
	public CommonResult<String> logout() {
		return this.userService.logout();
	}

	@ApiOperation("获取用户信息")
	@GetMapping("/user")
	public CommonResult<User> info() {
		return this.userService.info();
	}

	@ApiOperation("用户注册")
	@PostMapping("/register")
	public CommonResult<User> register(@RequestBody User user) {
		user.setId(null);
		return this.userService.register(user);
	}

	@ApiOperation("通过id修改用户信息")
	@PutMapping("/user")
	public CommonResult<String> update(@RequestBody User user) {
		return this.userService.update(user);
	}
}
